/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.serc.pensieve.data;
import com.sun.org.apache.xml.internal.utils.DefaultErrorHandler;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

 /*
 * @author Shani
 */
public class AdminDao {

    public void AddActor()
    {
    }
    
 public ArrayList<String> SelectSRS()
    {
      ArrayList<String> arrSRS = new ArrayList<String>();

        try {
            ResultSet res;
            DAO d = new DAO();
            Connection conn = d.makeConn();
            Statement stat = (Statement) conn.createStatement();
            String myQuery = "select * from srs";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int srsId;
            String srsName;
            while (res.next()) {
                srsId = res.getInt("ID");
                srsName = res.getString("SRSName");
                //Srs Ids at even places and names at odd places.
                arrSRS.add(Integer.toString(srsId));
                
                arrSRS.add(srsName);
                
           //   System.out.println("Id is :" + idTemp + " uname is : " + unameTemp + "urole is : " + roleTemp);
              
            }
                   } catch (ClassNotFoundException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        }
 return arrSRS;

    }
  public ArrayList<String> SelectCheckList()
    {
      ArrayList<String> arrSRS = new ArrayList<String>();

        try {
            ResultSet res;
            DAO d = new DAO();
            Connection conn = d.makeConn();
            Statement stat = (Statement) conn.createStatement();
            String myQuery = "select * from checklist";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int srsId;
            String srsName;
            while (res.next()) {
                srsId = res.getInt("ID");
                srsName = res.getString("CheckListName");
                //Srs Ids at even places and names at odd places.
                arrSRS.add(Integer.toString(srsId));

                arrSRS.add(srsName);

           //     System.out.println("Id is :" + idTemp + " uname is : " + unameTemp + "urole is : " + roleTemp);

            }
                   } catch (ClassNotFoundException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        }
 return arrSRS;

    }


 public ArrayList<String> SelectInspectors()
    {
      ArrayList<String> arrSRS = new ArrayList<String>();

        try {
            ResultSet res;
            DAO d = new DAO();
            Connection conn = d.makeConn();
            Statement stat = (Statement) conn.createStatement();
            String myQuery = "select * from pensieveusers where Role = 'Inspector'";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int srsId;
            String srsName;
            while (res.next()) {
                srsId = res.getInt("ID");
                srsName = res.getString("UserName");
                //Srs Ids at even places and names at odd places.
                arrSRS.add(Integer.toString(srsId));

                arrSRS.add(srsName);

           //     System.out.println("Id is :" + idTemp + " uname is : " + unameTemp + "urole is : " + roleTemp);

            }
                   } catch (ClassNotFoundException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        }
 return arrSRS;

    }

/* public ArrayList<String> SelectModerators()
    {
      ArrayList<String> arrSRS = new ArrayList<String>();

        try {
            ResultSet res;
            DAO d = new DAO();
            Connection conn = d.makeConn();
            Statement stat = (Statement) conn.createStatement();
            String myQuery = "select * from pensieveusers";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int srsId;
            String srsName;
            while (res.next()) {
                srsId = res.getInt("ID");
                srsName = res.getString("Moderator_Name");
                //Srs Ids at even places and names at odd places.
                arrSRS.add(Integer.toString(srsId));

                arrSRS.add(srsName);

           //     System.out.println("Id is :" + idTemp + " uname is : " + unameTemp + "urole is : " + roleTemp);

            }
                   } catch (ClassNotFoundException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        }
 return arrSRS;

    }*/
 
  public ArrayList<String> SelectModerators()
    {
      ArrayList<String> arrSRS = new ArrayList<String>();

        try {
            ResultSet res;
            DAO d = new DAO();
            Connection conn = d.makeConn();
            Statement stat = (Statement) conn.createStatement();
            String myQuery = "select * from pensieveusers where Role = 'Moderator'";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int srsId;
            String srsName;
            while (res.next()) {
                srsId = res.getInt("ID");
                srsName = res.getString("UserName");
                //Srs Ids at even places and names at odd places.
                arrSRS.add(Integer.toString(srsId));

                arrSRS.add(srsName);

           //     System.out.println("Id is :" + idTemp + " uname is : " + unameTemp + "urole is : " + roleTemp);

            }
                   } catch (ClassNotFoundException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
        }
 return arrSRS;

    }
 

     public ArrayList<String> login(String user, String pass) throws SQLException
     {
        boolean flag=false;
        ArrayList<String> arrRole = new ArrayList<String>();
 
        try
        {
            ResultSet res;
            DAO d = new DAO();
            String ali="ali";

            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQuery="select * from pensieveusers where UserName = '"+user+"' AND Password = '"+pass+"'";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int idTemp;
            String unameTemp;
            String roleTemp;
            while( res.next())
            {
                 idTemp =   res.getInt("Id");
                 unameTemp = res.getString("UserName");
                 roleTemp = res.getString("Role");
                // at even indexes=> role and at odd indexes there is ids of previous
                 arrRole.add(roleTemp);
                 arrRole.add(Integer.toString(idTemp));
                 
                 System.out.println("Id is :"+idTemp+" uname is : "+unameTemp + "urole is : "+roleTemp);
                 flag=true;
            }
 }
        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
             //  System.err.println("in user verify" + ex.getMessage());
        }
return arrRole;
  }


    public ArrayList<String> loginOne(int loginThisUsre_id) throws SQLException {
     boolean flag=false;
        ArrayList<String> arrRole = new ArrayList<String>();

        try
        {
            ResultSet res;
            DAO d = new DAO();
             String ali="ali";

            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQuery="select * from pensieveusers where Id = "+loginThisUsre_id;
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            int idTemp;
            String unameTemp;
            String roleTemp;
            String password;
            while( res.next())
            {
                 idTemp =   res.getInt("Id");
                 unameTemp = res.getString("UserName");
                 roleTemp = res.getString("Role");
                 password = res.getString("Password");
                 // at even indexes=> role and at odd indexes there is ids of previous

                 //Access 3 attributes in username, password and role pattern!.
                 arrRole.add(unameTemp);
                 arrRole.add(password);
                 arrRole.add(roleTemp);
                 
                 System.out.println("Id is :"+idTemp+" uname is : "+unameTemp + "urole is : "+roleTemp);
                 flag=true;
            }
 }
        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
             //  System.err.println("in user verify" + ex.getMessage());
        }
return arrRole;
     }

    
       public int SaveInspectors(String hsrs_id, String hsrs_name, String hcheck_id, String hcheck_name, ArrayList<String> arrSRS, ArrayList<String> arr1SRS) throws SQLException
       {
               int check=-1;

        try
        {
            ResultSet res;
            int length=arrSRS.size();
            DAO d = new DAO();
            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            int srs_id=Integer.parseInt(hsrs_id);
            int check_id=Integer.parseInt(hcheck_id);
            String myQueryx="insert into inspection (SRSID,CheckListID) values('"+srs_id+"','"+check_id+"')";
            stat.executeUpdate(myQueryx);
           
            String myQuery1="select * from inspection where SRSID = '"+srs_id+"' AND CheckListID='"+check_id+"' " ;
            System.out.println(myQuery1);
            res=stat.executeQuery(myQuery1);
            int inspection_id = 0;
            while( res.next())
            {
                 inspection_id =   res.getInt("ID");
                 break;
            }
            
            
                  // int j=0;
            for(int i=0;i<length;i++)
            {
                   int ins_id=Integer.parseInt(arrSRS.get(i));
                   int mod_id=Integer.parseInt(arr1SRS.get(0));
                   String myQuery3="insert into newinspection (Moderator_ID,InspectorID,InspectionID,SRSID,CheckListID,InspectionName,InspectionDescription) values('"+mod_id+"','"+ins_id+"','"+inspection_id+"','"+srs_id+"','"+check_id+"','Sample inspection','This is a sample discription')";
                   stat.executeUpdate(myQuery3);
                   i++;
                   check=1;
            }
           // String myQuery="select * from PensieveUsers where Id = "+loginThisUsre_id;
            //System.out.println(myQuery);
            //stat.executeQuery(myQuery);
            
        }
        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(AdminDao.class.getName()).log(Level.SEVERE, null, ex);
             //  System.err.println("in user verify" + ex.getMessage());
        }
        return check;
     }
        
       public int import_srs() throws SQLException
       {
       try{

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(true);

            DocumentBuilder builder = factory.newDocumentBuilder();
            builder.setErrorHandler(new DefaultErrorHandler());

            String filePath = "/home/farooq/NetBeansProjects/pensieve2/data/srs.xml";
            File xmlFile = new File(filePath);
            Document xmlDoc = builder.parse(xmlFile);
           int check=1;
           NodeList usecases = xmlDoc.getElementsByTagName("USECASE");
           NodeList srsname = xmlDoc.getElementsByTagName("SRSNAME");
           System.out.println("SRS NAME:" + srsname.item(0).getTextContent());
           
            NodeList srsdescription = xmlDoc.getElementsByTagName("SRSDESCRIPTION");
                System.out.println("SRS DESCRIPTION:" + srsdescription.item(0).getTextContent());
                
                   DAO d = new DAO();
            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQueryx="insert into srs (SRSName,SRSDescription) values('"+srsname.item(0).getTextContent()+"','"+srsdescription.item(0).getTextContent()+"')";
            stat.executeUpdate(myQueryx);
                

            for(int counter = 0; counter < usecases.getLength(); counter++ ){
                Element usecaselist = (Element) usecases.item(counter);
                
           NodeList actors = usecaselist.getElementsByTagName("ACTORS");
           NodeList preconditions = usecaselist.getElementsByTagName("PRECONDITIONS");
           NodeList mainflow = usecaselist.getElementsByTagName("FLOW");
           NodeList alternatives = usecaselist.getElementsByTagName("ALTERNATIVES");
           NodeList postconditions = usecaselist.getElementsByTagName("POSTCONDITIONS");
         
          
          
         
            
             ResultSet res; 
            String myQuery1="select ID from srs where SRSName = '"+srsname.item(0).getTextContent()+"' AND SRSDescription='"+srsdescription.item(0).getTextContent()+"' " ;
            System.out.println(myQuery1);
            res=stat.executeQuery(myQuery1);
            int srs_id = 0;
            while( res.next())
            {
                 srs_id =   res.getInt("ID");
     
            }
            
            
           NodeList usecasename = usecaselist.getElementsByTagName("USECASENAME");
                System.out.println("USECASE NAME:" + usecasename.item(0).getTextContent());
            
            NodeList description = usecaselist.getElementsByTagName("DESCRIPTION");
                System.out.println("DESCRIPTION:" + description.item(0).getTextContent());
              
           
              String myQuery="insert into usecases (UsecaseName,Description,SRSID,PreCondition,PostCondition,Mainflow,AlternativeFlow,Actors) values('"+usecasename.item(0).getTextContent()+"','"+description.item(0).getTextContent()+"','"+srs_id+"','"+preconditions.item(0).getTextContent()+"','"+postconditions.item(0).getTextContent()+"','"+mainflow.item(0).getTextContent()+"','"+alternatives.item(0).getTextContent()+"','"+actors.item(0).getTextContent()+"') ";
                    stat.executeUpdate(myQuery);

             //   if (titleList.item(0).getTextContent().equals("Pride & Prejudice")){
                    //System.out.println("Title:" + titleList.item(0).getTextContent());
                    //System.out.println("Author:" + book.getElementsByTagName("AUTHOR").item(0).getTextContent() );
                    //System.out.println("Binding:" + book.getElementsByTagName("BINDING").item(0).getTextContent() );
                    //System.out.println("Pages:" + book.getElementsByTagName("PAGES").item(0).getTextContent() );
             //   }
                
            }
           
  
//          System.out.println(xmlDoc.getElementsByTagName("TITLE").getLength());
//          System.out.println(xmlDoc.getElementsByTagNameNS("http://www.amazon.com/cds", "TITLE").getLength()) ;
            return 1;
        }
        catch (Exception ex){
             return 0;
            
        }
       
       }
       
       
        public int import_srs1() throws SQLException
       {
       try{

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(true);

            DocumentBuilder builder = factory.newDocumentBuilder();
            builder.setErrorHandler(new DefaultErrorHandler());

            String filePath = "/home/farooq/NetBeansProjects/pensieve2/data/srs.xml";
            File xmlFile = new File(filePath);
            Document xmlDoc = builder.parse(xmlFile);
           int check=1;
           NodeList usecases = xmlDoc.getElementsByTagName("USECASE");
           NodeList srsname = xmlDoc.getElementsByTagName("NAME");
           System.out.println("SRS NAME:" + srsname.item(0).getTextContent());

            for(int counter = 0; counter < usecases.getLength(); counter++ ){
                Element usecaselist = (Element) usecases.item(counter);
                
           NodeList actors = usecaselist.getElementsByTagName("ACTOR");
           NodeList preconditions = usecaselist.getElementsByTagName("PRECONDITION");
           NodeList steps = usecaselist.getElementsByTagName("STEP");
           NodeList alternatives = usecaselist.getElementsByTagName("ALTERNATIVE");
           NodeList postconditions = usecaselist.getElementsByTagName("POSTCONDITION");
         
          
           NodeList srsdescription = xmlDoc.getElementsByTagName("SRSDESCRIPTION");
                System.out.println("SRS DESCRIPTION:" + srsdescription.item(0).getTextContent());
                
            DAO d = new DAO();
            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQueryx="insert into srs (SRSName,SRSDescription) values('"+srsname.item(0).getTextContent()+"','"+srsdescription.item(0).getTextContent()+"')";
            stat.executeUpdate(myQueryx);
            
            
             Element usecasenam = (Element) usecaselist.getElementsByTagName("USECASENAME");
             NodeList usecasename = usecasenam.getElementsByTagName("UNAME");
                System.out.println("USECASE NAME:" + usecasename.item(0).getTextContent());
            ResultSet res; 
            String myQuery1="select ID from srs where SRSName = '"+srsname.item(0).getTextContent()+"' AND SRSDescription='"+srsdescription.item(0).getTextContent()+"' " ;
            System.out.println(myQuery1);
            res=stat.executeQuery(myQuery1);
            int srs_id = 0;
            while( res.next())
            {
                 srs_id =   res.getInt("ID");
                 break;
            }
            NodeList description = usecaselist.getElementsByTagName("DESCRIPTION");
                System.out.println("DESCRIPTION:" + description.item(0).getTextContent());
                String myQuery;
                if(check==1)
                {
                    myQuery="insert into usecase (UsecaseName,Description,SRSID) values('"+usecasename.item(0).getTextContent()+"','"+description.item(0).getTextContent()+"','"+srs_id+"')";
                    stat.executeUpdate(myQuery);
                    check=0;
                }
                
               
               
            String myQuery2="select id from usecase where SRSID = '"+srs_id+"' AND UsecaseName='"+usecasename.item(0).getTextContent()+"' " ;
            System.out.println(myQuery2);
            res=stat.executeQuery(myQuery2);
            int usecase_id = 0;
            while( res.next())
            {
                 usecase_id =   res.getInt("id");
                 break;
            }
            
             
            
            for(int counter1 = 0; counter1 < actors.getLength(); counter1++ ){
                // actorlist = (NodeList) actors.item(counter1);
                 System.out.println("ACTORS:" + actors.item(counter1).getTextContent());
                  myQuery="insert into actors (srsid,usecaseid,name) values('"+srs_id+"','"+usecase_id+"','"+actors.item(counter1).getTextContent()+"')";
                  stat.executeUpdate(myQuery);
             }
                 
                String myQuery3;
             for(int counter2 = 0; counter2 < preconditions.getLength(); counter2++ ){
                 //preconditionlist =  (NodeList) preconditions.item(counter2);
                     System.out.println("PRECONDITIONS:" + preconditions.item(counter2).getTextContent());
                     myQuery3="insert into preconditions (srsid,usecaseid,precondition) values('"+srs_id+"','"+usecase_id+"','"+preconditions.item(counter2).getTextContent()+"')";
                     stat.executeUpdate(myQuery3);
             }
             String myQuery4;
             for(int counter3 = 0; counter3 < steps.getLength(); counter3++ ){
             //    steplist =  (NodeList) steps.item(counter3);
                 System.out.println("STEPS:" + steps.item(counter3).getTextContent());
                  myQuery4="insert into mainflow (srsid,usecaseid,steps) values('"+srs_id+"','"+usecase_id+"','"+steps.item(counter3).getTextContent()+"')";
                     stat.executeUpdate(myQuery4);
             }
             
              for(int counter4 = 0; counter4 < alternatives.getLength(); counter4++ ){
            //     alternativelist =  (NodeList) alternatives.item(counter4);
                 System.out.println("ALTERNATIVES:" + alternatives.item(counter4).getTextContent());
                 myQuery="insert into alternatives (srsid,usecaseid,alternative) values('"+srs_id+"','"+usecase_id+"','"+alternatives.item(counter4).getTextContent()+"')";
                     stat.executeUpdate(myQuery);
             }
              
               for(int counter5 = 0; counter5 < postconditions.getLength(); counter5++ ){
                // postconditionlist =  (NodeList) postconditions.item(counter5);
                   System.out.println("POSTCONDITIONS:" + postconditions.item(counter5).getTextContent());
                    myQuery="insert into postconditions (srsid,usecaseid,postcondition) values('"+srs_id+"','"+usecase_id+"','"+postconditions.item(counter5).getTextContent()+"')";
                     stat.executeUpdate(myQuery);
             }

             //   if (titleList.item(0).getTextContent().equals("Pride & Prejudice")){
                    //System.out.println("Title:" + titleList.item(0).getTextContent());
                    //System.out.println("Author:" + book.getElementsByTagName("AUTHOR").item(0).getTextContent() );
                    //System.out.println("Binding:" + book.getElementsByTagName("BINDING").item(0).getTextContent() );
                    //System.out.println("Pages:" + book.getElementsByTagName("PAGES").item(0).getTextContent() );
             //   }
                
            }
           
  
//          System.out.println(xmlDoc.getElementsByTagName("TITLE").getLength());
//          System.out.println(xmlDoc.getElementsByTagNameNS("http://www.amazon.com/cds", "TITLE").getLength()) ;
            return 1;
        }
        catch (Exception ex){
             return 0;
            
        }
       
       }
       
        
        public int import_checklist() throws SQLException
       {
           
            try{

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(true);

            DocumentBuilder builder = factory.newDocumentBuilder();
            builder.setErrorHandler(new DefaultErrorHandler());

            String filePath = "/home/farooq/NetBeansProjects/pensieve2/data/test_checklist.xml";
            File xmlFile = new File(filePath);
            Document xmlDoc = builder.parse(xmlFile);
            int check=1;
           
         
           NodeList points = xmlDoc.getElementsByTagName("POINT");
           NodeList checklistname = xmlDoc.getElementsByTagName("CHECKLISTNAME");
           NodeList checklistdescription = xmlDoc.getElementsByTagName("CHECKLISTDESCRIPTION");
           System.out.println("CHECK NAME:" + checklistname.item(0).getTextContent());
           System.out.println("CHECK DESCRIPTION:" + checklistdescription.item(0).getTextContent());
                
            DAO d = new DAO();
            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQueryx="insert into checklist (CheckListName,CheckListDescription) values('"+checklistname.item(0).getTextContent()+"','"+checklistdescription.item(0).getTextContent()+"')";
            stat.executeUpdate(myQueryx);
            
           
            ResultSet res; 
            String myQuery1="select ID from checklist where CheckListName = '"+checklistname.item(0).getTextContent()+"' AND CheckListDescription='"+checklistdescription.item(0).getTextContent()+"' " ;
            System.out.println(myQuery1);
       
            res=stat.executeQuery(myQuery1);
            int check_id = 0;
            
           
            while( res.next())
            {
                 check_id =   res.getInt("ID");
                 break;
            }
                   
            
          for(int counter = 0; counter < points.getLength(); counter++ ){
                Element point = (Element) points.item(counter);
                
                
             String myQuery4;
            
             NodeList heading = point.getElementsByTagName("HEADING");
             NodeList description = point.getElementsByTagName("DESCRIPTION");
                 System.out.println("HEADING:" + heading.item(0).getTextContent());
                 System.out.println("HEADING:" + description.item(0).getTextContent());
                 
                 myQuery4="insert into checklistdata (CheckListID,Heading,Description) values('"+check_id +"','"+heading.item(0).getTextContent()+"','"+description.item(0).getTextContent()+"')";
                  stat.executeUpdate(myQuery4);
             }
             
            
             
             
             
                
           
  
//          System.out.println(xmlDoc.getElementsByTagName("TITLE").getLength());
//          System.out.println(xmlDoc.getElementsByTagNameNS("http://www.amazon.com/cds", "TITLE").getLength()) ;
            return 1;
        }
        catch (Exception ex){
            return 0;
        }
            
            
       }
        
        public int import_checklist1() throws SQLException
       {
           
            try{

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(true);

            DocumentBuilder builder = factory.newDocumentBuilder();
            builder.setErrorHandler(new DefaultErrorHandler());

            String filePath = "/home/farooq/NetBeansProjects/pensieve2/data/catalog1.xml";
            File xmlFile = new File(filePath);
            Document xmlDoc = builder.parse(xmlFile);
            int check=1;
           
         
           NodeList points = xmlDoc.getElementsByTagName("POINT");
           NodeList checklistname = xmlDoc.getElementsByTagName("CHECKLISTNAME");
           NodeList checklistdescription = xmlDoc.getElementsByTagName("CHECKLISTDESCRIPTION");
           System.out.println("CHECK NAME:" + checklistname.item(0).getTextContent());
           System.out.println("CHECK DESCRIPTION:" + checklistdescription.item(0).getTextContent());
                
            DAO d = new DAO();
            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQueryx="insert into checklist (CheckListName,CheckListDescription) values('"+checklistname.item(0).getTextContent()+"','"+checklistdescription.item(0).getTextContent()+"')";
            stat.executeUpdate(myQueryx);
            
           
            ResultSet res; 
            String myQuery1="select ID from checklist where CheckListName = '"+checklistname.item(0).getTextContent()+"' AND CheckListDescription='"+checklistdescription.item(0).getTextContent()+"' " ;
            System.out.println(myQuery1);
            res=stat.executeQuery(myQuery1);
            int check_id = 0;
            
           
            /*while( res.next())
            {
                 check_id =   res.getInt("ID");
                 break;
            }*/
            
          for(int counter = 0; counter < points.getLength(); counter++ ){
                Element point = (Element) points.item(counter);
                
                
             String myQuery4;
            
             NodeList heading = point.getElementsByTagName("HEADING");
             NodeList description = point.getElementsByTagName("DESCRIPTION");
                 System.out.println("HEADING:" + heading.item(0).getTextContent());
                 System.out.println("HEADING:" + description.item(0).getTextContent());
                 
                 myQuery4="insert into checklistdata (CheckListID,Heading,Description) values('"+check_id +"','"+heading.item(0).getTextContent()+"','"+description.item(0).getTextContent()+"')";
                  stat.executeUpdate(myQuery4);
             }
             
            
             
             
             
                
           
  
//          System.out.println(xmlDoc.getElementsByTagName("TITLE").getLength());
//          System.out.println(xmlDoc.getElementsByTagNameNS("http://www.amazon.com/cds", "TITLE").getLength()) ;
            return 1;
        }
        catch (Exception ex){
            return 0;
        }
            
            
       }

   
        
  }



